package com.baishancloud.log.fm

import scala.beans.BeanProperty

/**
 *
 * @author ziqiang.wang 
 * @date 2021/12/1 15:18
 */
class Calculate extends Serializable {}


/**
 * @param time           日志时间，秒值
 * @param host           host
 * @param httpCode       http_code
 * @param hit            是否命中：0、1
 * @param domain         域名，原始字符串，不处理
 * @param source         数据来源：LUBAN/BLB
 * @param isIpv4         是否为ipv4，0/1，包含英文逗号的为v4
 * @param upstreamStatus 上游回源状态码
 * @param request        请求次数，日志条数
 * @param firstBagTime   首包时长
 * @param traffic        流量
 * @param timeResponse   响应时间
 *
 */
case class Log(@BeanProperty time: Long, @BeanProperty host: String, @BeanProperty httpCode: Int, @BeanProperty hit: Byte, @BeanProperty domain: String, @BeanProperty source: String, @BeanProperty isIpv4: Byte, @BeanProperty upstreamStatus: Int, @BeanProperty request: Long, @BeanProperty firstBagTime: Long, @BeanProperty traffic: Long, @BeanProperty timeResponse: Long) extends Serializable {
  def getKey: LogKey = {
    LogKey(time, host, httpCode, hit, domain, source, isIpv4, upstreamStatus)
  }

  def getValue: LogValue = {
    LogValue(request, firstBagTime, traffic, timeResponse)
  }
}

object Log {
  def apply(key: LogKey, value: LogValue): Log = new Log(key.time, key.host, key.httpCode, key.hit, key.domain, key.source, key.isIpv4, key.upstreamStatus, value.request, value.firstBagTime, value.traffic, value.timeResponse)
}

case class LogKey(time: Long, host: String, httpCode: Int, hit: Byte, domain: String, source: String, isIpv4: Byte, upstreamStatus: Int) extends Serializable

case class LogValue(request: Long, firstBagTime: Long, traffic: Long, timeResponse: Long) extends Serializable



